package com.lepai.component;

import com.lepai.service.impl.UserServiceImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author weihaolong
 * @date 2018-11-28 9:13:00
 * @description
 */
@Component
public class MyFactoryBean implements FactoryBean<UserServiceImpl>, InitializingBean, DisposableBean {
    Logger logger = LogManager.getLogger();

    @Autowired
    private UserServiceImpl userServiceImpl;

    @Override
    public void destroy() throws Exception {
        if(logger.isTraceEnabled()) {
            logger.trace(getClass() + "MyFactoryBean destroy...");
        }
    }

    @Override
    public UserServiceImpl getObject() throws Exception {
        return userServiceImpl;
    }

    @Override
    public Class<?> getObjectType() {
        return userServiceImpl.getClass();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info(getClass() + " MyFactoryBean after...");
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
